
const project_config = require('./project_config');

const table_page_generate = require('./generates/table_page_generate');
const router_generate = require('./generates/router_generate');
const api_generate = require('./generates/api_config_generate');
const login_register_generate = require('./generates/login_register_generate');
const nav_left_menu_generate = require('./generates/nav_left_menu_generate');
const add_page_generate = require('./generates/add_page_generate');
const detail_page_generate = require('./generates/detail_page_generate');

const bg_editor_generate = require('./generates/bg_editor_generate');

const tool = require('./tool');

root_generate();

async function root_generate() {

  //在上层生成src文件夹
  await tool.testAndMakeDirectory({
    dirPath: '../src'
  });
  
  //路由生成
  router_generate(project_config);
  //api接口生成
  api_generate(project_config);
  //导航菜单生成
  nav_left_menu_generate(project_config);

  //创建文件
  for (var item in project_config) {
    if (item == 'admin') {
      login_register_generate(project_config[item], project_config);
      continue;
    }
    for (var subItem in project_config[item]) {
      if (subItem.includes('table')) {
        //表格配置 模块配置
        table_page_generate(project_config[item][subItem], project_config[item]);
      }
      if (subItem.includes('add_page')) {
        add_page_generate (project_config[item], project_config[item][subItem]);
      }
      if (subItem.includes('bg_editor_page')) {
        bg_editor_generate (project_config[item], project_config[item][subItem]);
      }

      if (subItem.includes('detail_page')) {
        detail_page_generate ( project_config[item], project_config[item][subItem] );
      }
    }
  }

}











